package cc.wanforme.chipmunity.controller;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cc.wanforme.chipmunity.controller.base.BaseController;

@Controller
@RequestMapping("/upload")
public class UploadController extends BaseController{
	private static final Logger log = LoggerFactory.getLogger(UploadController.class);
	
	
	/**
     * 图片上传接口,主要是用于UEditor图片上传,并且返回对应的数据格式
     * @param upfile
     * @return
     */
    @RequestMapping(value = "/image", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, String> uploadimage(@RequestParam(value = "upfile") MultipartFile[] upfile) {
        Map<String, String> map = new HashMap<>();
        
//        String picUrls = "";
        try {
        	byte[] bytes = upfile[0].getBytes();
            map.put("url", Base64Utils.encodeToUrlSafeString(bytes));
            map.put("state", "SUCCESS");
            map.put("original", "");
        } catch (Exception e) {
            log.error("uploadimage", e);
        }
        
        System.out.println("map: \n" + map);
        
        return map;
    }
	
    
}
